package cate.game.play.skill.passive.hero;

import cate.game.play.config.PlayCfgArgs;
import cate.game.play.fighter.Fighter;
import cate.game.play.proce.action.ctx.ActionCtx;
import cate.game.play.proce.action.ctx.SkillActionCtx;
import cate.game.play.proce.move.AppendMove;
import cate.game.play.proce.move.AppendMoveHandler;
import cate.game.play.proce.turn.TurnCtx;
import cate.game.play.skill.Skill;
import cate.game.play.skill.passive.PassiveHandler;

/**
 * 攻击造成伤害时，100%叠加1层【天使羽翼】，单个回合最多触发6次；
 * 天使羽翼达到15层，发动无视控制技能【制裁八方】：
 */
public class 天使之力PH extends PassiveHandler implements AppendMoveHandler {


	private int 概率;

	private int buff;

	private int 回合次数;

	private int 技能层数;

	private int 追加技能;

	//概率=10000&buff=？？&回合次数=6&技能层数=？？&追加技能=？？
	@Override
	public void parse(String code) {
		PlayCfgArgs args = new PlayCfgArgs(code);
		概率 = args.getInt("概率", 0);
		buff = args.getInt("buff", 0);
		回合次数 = args.getInt("回合次数", 0);
		技能层数 = args.getInt("技能层数", 0);
		追加技能 = args.getInt("追加技能", 0);
	}

	@Override
	public void parseExt(String code) {
		PlayCfgArgs args = new PlayCfgArgs(code);
		技能层数 += args.getInt("技能层数", 0);
	}

	private int roundAdd;


	@Override
	public void onRoundBegin(ActionCtx action) {
		roundAdd = 0;
	}

	@Override
	public void afterOneAttack(SkillActionCtx action, long totalDamage, boolean strike, Fighter target) {
		if (totalDamage <= 0) {
			return;
		}
		if (roundAdd >= 回合次数) {
			return;
		}
		int i = skill.owner.buff.tryAddByTid(action, skill.owner, buff, 概率);
		if (i > 0) {
			roundAdd++;
			int buffNum = skill.owner.buff.countBuffByTid(buff);
			handleAppend(action,buffNum);
		}
	}


	private void handleAppend(SkillActionCtx action, int buffNum) {
		if (技能层数 <= 0) {
			return;
		}
		if (buffNum % 技能层数 != 0) {
			return;
		}
		Skill appendSkill = action.getCfg().skill.buildById(skill.owner, 追加技能);
		if (appendSkill == null) {
			return;
		}
		appendSkill.param.setIgnCtrlMove(true);
		action.getTurn().addAppend(new AppendMove(skill.owner, appendSkill,this));
	}

	@Override
	public boolean inValid(TurnCtx turn, AppendMove appendMove) {
		return false;
	}

	@Override
	public void beforeAppendMove(TurnCtx turn, AppendMove appendMove) {
		skill.owner.buff.removeBuffByTid(turn.buildTimeAction(), buff);
	}

	@Override
	public void afterAppendMove(TurnCtx turn, AppendMove appendMove) {

	}

	@Override
	public void onAppendMoveFail(TurnCtx turn, AppendMove appendMove) {

	}
}
